package killer.board.qna.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import killer.board.qna.model.QnaBoardVO;
import killer.board.qna.service.QnaBoardService;
import killer.paging.ListVO;

@Controller
public class QnaBoardController {
	
	@Resource(name="qnaBoardService")
	private QnaBoardService qnaBoardService;
	
	@RequestMapping(value="getQnaBoardList.killer")
	public ModelAndView getQnaList(int nowPage) throws Exception{
		ListVO listVO=this.qnaBoardService.getBoardWritingList(nowPage);
		return new ModelAndView("board/qna/getQnaBoardList.board","qnaListVO",listVO);
	}
	
	@RequestMapping(value="getQnaBoardByNo.killer")
	public ModelAndView getQnaByNo(int qnaNo) throws Exception{
		QnaBoardVO qbvo=(QnaBoardVO) this.qnaBoardService.getBoardWritingByNo(qnaNo);
		return new ModelAndView("board/qna/getQnaBoardByNo.board", "qbvo", qbvo);
	}
	
	@RequestMapping(value="writeQnaPage.killer")
	public String registerQnaPage(QnaBoardVO paramQbvo) throws Exception{
		return "board/qna/write.board";
	}
	
	@RequestMapping(value="writeQna.killer")
	public String registerQna(@ModelAttribute("qbvo") QnaBoardVO paramQbvo) throws Exception{
		QnaBoardVO qbvo=(QnaBoardVO) this.qnaBoardService.registerBoardWriting(paramQbvo);
		return "board/qna/getQnaBoardByNo.board";
	}

	
	@RequestMapping(value="writeQnaReply.killer")
	public String registerQnaReply(@ModelAttribute("qbvo") QnaBoardVO paramQbvo) throws Exception{
		System.out.println(paramQbvo);
		this.qnaBoardService.registerReply(paramQbvo);
		System.out.println("RE: "+paramQbvo);
		return "board/qna/getQnaBoardByNo.board";
	}
	
	
}














